﻿// CMakeIbot.h: 标准系统包含文件的包含文件
// 或项目特定的包含文件。

#pragma once
#include "../common/common.hpp"
#include "TYImageProc.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <pcl/console/parse.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/common/io.h>
#include <pcl/common/common.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/ransac.h>
#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/sample_consensus/sac_model_sphere.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <limits>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include "TYImageProc.h"
#include <opencv2/opencv.hpp>
#include <string>


struct CallbackData {
  int             index;
  TY_ISP_HANDLE   IspHandle;
  TY_DEV_HANDLE   hDevice;
  DepthRender*    render;
  DepthViewer*    depthViewer;
  bool            needUndistort;

  float           scale_unit;

  bool            isTof;
  TY_CAMERA_CALIB_INFO depth_calib;
  TY_CAMERA_CALIB_INFO color_calib;
};


class CameraController  {

public:
    explicit CameraController();
    ~CameraController();

    bool initializeCamera(std::string ID,std::string IP);

    bool startCapture();

    bool stopCapture();
    bool closeCamera();
    CallbackData cb_data;
    char* frameBuffer[2];
    TY_INTERFACE_HANDLE hIface;
    TY_DEV_HANDLE hDevice;

    void frameReady(const cv::Mat &frame);

private:

    static void doRegister(const TY_CAMERA_CALIB_INFO& depth_calib
                           , const TY_CAMERA_CALIB_INFO& color_calib
                           , const cv::Mat& depth
                           , const float f_scale_unit
                           , const cv::Mat& color
                           , bool needUndistort
                           , cv::Mat& undistort_color
                           , cv::Mat& out
                           , bool map_depth_to_color
                           );
    static void handleFrame(TY_FRAME_DATA* frame, void* userdata);
    static void eventCallback(TY_EVENT_INFO *event_info, void *userdata);
};





